<template>
  <div>
    <div class="cbody">
      <div class="top">
        <div :class="dayChange == 0 ? 'hac' : ''" @click="setDays(0)">全部</div>
        <div :class="dayChange == 1 ? 'hac' : ''" @click="setDays(1)">今日</div>
        <div :class="dayChange == 2 ? 'hac' : ''" @click="setDays(2)">近7天</div>
        <div :class="dayChange == 3 ? 'hac' : ''" @click="setDays(3)">近30天</div>
      </div>
      <div class="info">
        <div class="head">
          <div>
            <div class="name">服务商收入</div>
            <div class="count">￥{{money.pt.toFixed(2)}}</div>
          </div>
          <div>
            <div class="name">服务商数量</div>
            <div class="count">{{money.hh}}</div>
          </div>
          <div>
            <div class="name">账户余额</div>
            <div class="count">￥{{money.fw.toFixed(2)}}</div>
          </div>
          <div>
            <div class="name">已提现金额</div>
            <div class="count">￥{{money.yj.toFixed(2)}}</div>
          </div>
        </div>
        <div class="screen">服务商列表</div>
        <!-- <div class="sel">
            <span>名称：</span>
            <input type="text" placeholder="服务商名称/合伙人" v-model="params.keyWord">
            <span>当前状态：</span>
            <select name  v-model="params.states">
              <option value="">请选择</option>
              <option value="0">待审核 </option>
              <option value="1">审核通过未打款 </option>
              <option value="2">审核通过已打款 </option>
              <option value="3">审核失败</option>
            </select>
            <div class="sel-btn">查询</div>
        </div>-->
        <div v-loading="loading">
          <div class="parchange">
            <div :class="params.ord== 1 ? 'aced' : ''" @click="setType(1)">默认</div>
            <div :class="params.ord== 2 ? 'aced' : ''" @click="setType(2)">收入</div>
            <div :class="params.ord== 3 ? 'aced' : ''" @click="setType(3)">提现</div>
            <div :class="params.ord== 4 ? 'aced' : ''" @click="setType(4)">余额</div>
          </div>
          <div class="table">
          <div class="thead">
            <div class="username">服务商名称</div>
            <div class="parsr">服务商收入</div>
            <div class="txmoney">已提现金额</div>
            <div class="accmoney">账户余额</div>
            <div class="ptmoney">平台佣金</div>
            <div class="ctrl">操作</div>
          </div>
          <div class="tbody" v-for="(item,index) in list" :key="index">
            <div class="username firstchild">
              <span :title="item.service_name">{{ item.service_name }}</span>
            </div>
            <div class="parsr">
              <span>￥ {{ item.shou.toFixed(2)}}</span>
            </div>
            <div class="txmoney">￥{{ item.ti.toFixed(2) }}</div>
            <div class="accmoney">￥{{ item.balance.toFixed(2) }}</div>
            <div class="ptmoney">￥{{item.commission.toFixed(2)}}</div>
            <div
              v-if="roleList.search('财务管理') != '-1'"
              class="ctrl"
              style="color:#085dab"
              @click="details(item.id)"
            >收入明细</div>
          </div>
        </div>
          <!-- <el-table :data="list" border style="width: 100%">
            <el-table-column prop="service_name" label="合伙人名称"></el-table-column>
            <el-table-column prop="shou" label="服务商收入">
              <template slot-scope="scope">
                <p>￥{{ scope.row.shou.toFixed(2)}}</p>
              </template>
            </el-table-column>
            <el-table-column prop="ti" label="已提现金额">
              <template slot-scope="scope">
                <p>￥{{ scope.row.ti.toFixed(2)}}</p>
              </template>
            </el-table-column>
            <el-table-column label="账户余额">
              <template slot-scope="scope">
                <p>￥{{ scope.row.balance.toFixed(2)}}</p>
              </template>
            </el-table-column>
            <el-table-column prop="date" label="操作">
              <template slot-scope="scope">
                <span
                  v-if="roleList.indexOf('财务管理') != '-1'"
                  @click="details( scope.row.id )"
                  style="color:#085dab;cursor:pointer"
                >收入明细</span>
              </template>
            </el-table-column>
          </el-table> -->
          <div style="text-align: center;padding: 50px 0;">
            <el-pagination
              background
              layout="prev, pager, next"
              :page-count="pageTotal"
              @current-change="changePage"
            ></el-pagination>
          </div>
        </div>
        
      </div>
    </div>
    <div class="clear"></div>
    <div class="popup_details" ref="popup_details">
      <el-table
          :data="detailsList"
          border
          style="width: 100%"
          >
          <el-table-column
            prop="title"
            label="活动名称"
            >
          </el-table-column>
          <el-table-column
            prop="price"
            label="报名费用（元）"
            >
            <template slot-scope="scope">
              {{ scope.row.price.toFixed(2)}}
            </template>
          </el-table-column>
          
          <el-table-column
            prop="bi"
            label="服务商分成比例"
            >
            <template slot-scope="scope">
              {{ scope.row.bi}}%
            </template>
          </el-table-column>
          <el-table-column
            prop="ping"
            label="平台佣金（元）"
            >
            <template slot-scope="scope">
              {{ scope.row.ping.toFixed(2)}}
            </template>
          </el-table-column>
          <el-table-column
            prop="mendian"
            label="分成金额（元）"
            >
            <template slot-scope="scope">
              {{ scope.row.mendian.toFixed(2)}}
            </template>
          </el-table-column>
          <el-table-column
            prop="time"
            label="结算时间"
            >
            <template slot-scope="scope">
              {{ new Date ( scope.row.time ).toLocaleDateString () }}
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
      class="el-pagination"
      background
      layout="prev, pager, next"
      :page-count="detailsTotal"
      @current-change="detailsChangePage"
    ></el-pagination>
    </div>
    
  </div>
</template>

<style type="text/scss" lang="scss" scoped>
.popup_details {
  display: none;
  text-align: center;
  width: 100%;
  height: 100%;
  overflow-y: scroll;
  .el-pagination {
    margin: 50px 0;
  }
}
</style>

<script>
import Global from "../tool/Global.vue";
import axios from "axios";
import qs from "qs"; // 将请求转换成form 表单提交形式
export default {
  created() {
    this.getFinList();
    this.getTotal();
    this.getRole();
  },
  data() {
    return {
      loading: false,
      params: {
        keyWord: "",
        // states:1,
        limit: 10,
        page: 1,
        // type:0
        ord: 1
      },
      money: {
        pt: "",
        hh: "",
        fw: "",
        yj: ""
      },
      list: [],
      info: {},
      pageTotal: 1,
      dayChange: 0,
      types: "",
      detailsList: [],
      detailsTotal: 1,
      detailsId: "",
      detailsPage: {
        page: 1
      },
      roleList: ""
    };
  },
  methods: {
    /**
     *  获取权限
     */
    getRole: function() {
      let that = this;
      axios({
        method: "post",
        url: `${that.$store.state.url}/sysPermission/selectByEmployeeId`,
        data: qs.stringify({
          empId: that.$cookie.get("pid")
        })
      }).then(res => {
        let arr = res.data.data;
        let role = [];
        for (let i = 0; i < arr.length; i++) {
          role.push(arr[i].name);
        }
        this.roleList = role.toString();
      });
    },
    // 列表分页
    changePage(argv) {
      this.params.page = argv;
      this.getFinList();
    },
    // 弹窗分页
    detailsChangePage(argv) {
      this.detailsPage.page = argv;
      this.getDetails();
    },
    // 获取弹窗信息
    getDetails() {
      axios
        .post(
          `${this.$store.state.url}/tWithdrawal/selectDateilByService `,
          qs.stringify({
            serviceId: this.detailsId,
            page: this.detailsPage.page,
            limit: 10
          })
        )
        .then(response => {
          let res = response.data;
          if (res.code == 0) {
            this.detailsList = res.data;
            this.detailsTotal = Math.ceil(res.count / 10);
          }
        });
    },

    // 显示详情弹窗
    details(id) {
      let _this = this;
      this.detailsId = id;
      this.detailsList = [];
      this.getDetails();

      layer.open({
        type: 1,
        zIndex: 1,
        title: false,
        closeBtn: false,
        shadeClose: true,
        area: ["800px", "550px"],
        content: $(_this.$refs.popup_details),
        btn: false,
        end() {
          _this.$refs.popup_details.style.display = "none";
        }
      });
    },
    /**
     * 设置状态
     */
    setType: function(num) {
      this.params.ord = num;
      this.getFinList();
    },
    // 获取统计数据
    getTotal() {
      axios
        .post(
          `${this.$store.state.url}/tWithdrawal/selectMoneyByPartner`,
          qs.stringify({
            type: 1
          })
        )
        .then(response => {
          let res = response.data;
          if (res.code == 0) {
            this.info = res.data;
            this.setDays(0);
          }
        });
    },
    /**
     *  设置天数
     */
    setDays: function(num) {
      let that = this;
      this.dayChange = num;
      switch (num) {
        case 0:
          this.money = {
            pt: this.info.partnerTotalPrice,
            hh: this.info.partnerNum,
            fw: this.info.totalPrice,
            yj: this.info.backstageTotalPrice
          };
          break;
        case 1:
          this.money = {
            pt: this.info.partnerTodayTotalPrice,
            hh: this.info.partnerTodayNum,
            fw: this.info.totalTodayPrice,
            yj: this.info.backstageTodayTotalPrice
          };
          break;
        case 2:
          this.money = {
            pt: this.info.totalWeekPrice,
            hh: this.info.partnerWeekNum,
            fw: this.info.totalWeekPrice,
            yj: this.info.backstageWeekTotalPrice
          };
          break;
        case 3:
          this.money = {
            pt: this.info.totalMonPrice,
            hh: this.info.partnerMonNum,
            fw: this.info.totalMonPrice,
            yj: this.info.backstageMonTotalPrice
          };
          break;
      }
      console.log(this.money);
    },
    /**
     *  查询财务列表
     */
    getFinList: function(num) {
      // let that = this;
      this.loading = true;
      let _this = this;
      axios
        .post(
          // `${this.$store.state.url}/tWithdrawal/selectDrawal`,
          `${this.$store.state.url}/tWithdrawal/selectServiceByWithList`,
          qs.stringify(this.params)
        )
        .then(
          response => {
            let res = response.data;
            if (res.code == 0) {
              this.pageTotal = Math.ceil(res.count / 10);
              _this.list = res.data;
            }
            this.loading = false;
          },
          () => {
            this.loading = false;
          }
        );
    },
    /*
     * 根据时间毫秒数 返回年月日
     */
    setDate: function(str) {
      let times = new Date(str);
      return `${times.getFullYear()}-${
        times.getMonth() < 10 ? "0" + times.getMonth() : times.getMonth()
      }-${times.getDate() < 10 ? "0" + times.getDate() : times.getDate()}`;
    },
    /**
     * 根据时间毫秒数 返回时分秒
     */
    setTime: function(str) {
      let times = new Date(str);
      return `${
        times.getHours() < 10 ? "0" + times.getHours() : times.getHours()
      }:${
        times.getMinutes() < 10 ? "0" + times.getMinutes() : times.getMinutes()
      }:${
        times.getSeconds() < 10 ? "0" + times.getSeconds() : times.getSeconds()
      }`;
    }
  },
  mounted() {}
};
</script>
<style scoped>
.screen,
.parchange {
  /* width: 1520px; */
  height: 60px;
  background: #f6f6f6;
  line-height: 60px;
  font-family: PingFangSC-Medium;
  margin-top: 30px;
  margin-bottom: 26px;
  font-size: 18px;
  color: #000000;
  font-weight: bold;
  padding-left: 24px;
  box-sizing: border-box;
}
.parchange {
  padding: 0;
}
.parchange > div {
  display: inline-block;
  width: 110px;
  height: 36px;
  text-align: center;
  border-right: 1px solid #ddd;
  line-height: 36px;
  margin-top: 12px;
  cursor: pointer;
}
.parchange > div:last-of-type {
  height: 60px;
  margin-top: 0;
  line-height: 60px;
}
.parchange .aced {
  color: #085dab;
}
.screen img {
  float: left;
  width: 27px;
  height: 27px;
  margin-left: 10px;
  margin-top: 16px;
  margin-right: 18px;
}
.sel {
  height: 40px;
  line-height: 40px;
  width: 1520px;
}
.sel > span {
  font-weight: bold;
  font-size: 18px;
  color: #000000;
  float: left;
}
.sel > span:last-of-type {
  margin-left: 106px;
}
.sel > input {
  background: #ffffff;
  border: 1px solid #979797;
  box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.5);
  width: 317px;
  height: 38px;
  font-size: 18px;
  color: #888888;
  text-align: center;
  float: left;
  outline: none;
}
.sel > select {
  background: #ffffff;
  border: 1px solid #979797;
  box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.5);
  width: 317px;
  height: 38px;
  font-size: 18px;
  color: #888888;
  text-align: center;
  float: left;
  outline: none;
  padding-left: 70px;
}
.sel-btn {
  background: #085dab;
  border: 1px solid #085dab;
  width: 140px;
  height: 38px;
  font-size: 18px;
  color: #ffffff;
  text-align: center;
  float: left;
  margin-left: 50px;
  cursor: pointer;
}

.cbody {
  /* float: left; */
  padding-top: 25px;
}
.info {
  /* width: 1504px; */

  height: 140px;
  background: #f6f6f6;
  margin-left: 4px;
}
.top {
  /* margin-top: 7px; */
  height: 40px;
  text-align: center;
  width: 440px;
  color: #1875f0;
  border: 2px solid #1875f0;
  box-sizing: border-box;
  border-radius: 4px;
  display: flex;
  /* margin-bottom: 38px;
  margin-left: 476px; */
  margin: 0 auto 25px;
}
.top > div {
  flex: 1;
  /* height: 40px; */
  line-height: 40px;
  font-size: 14px;
  border-left: 2px solid #1875f0;
  box-sizing: border-box;
  font-weight: bold;
  cursor: pointer;
}
.top :first-child {
  border: 0;
}
.top .hac {
  background: #1875f0;
  color: #fff;
}
.head {
  display: flex;
  /* width: 1520px; */
}
.head > div {
  flex: 1;
  border-left: 1px solid #fff;
  height: 140px;
  background: #f6f6f6;
}
.head :first-child {
  border-left: 0px solid #fff;
}
.name {
  font-size: 18px;
  color: #000000;
  height: 24px;
  text-align: center;
  margin-top: 23px;
  margin-bottom: 27px;
  font-weight: bold;
}
.count {
  height: 50px;
  font-size: 36px;
  color: #085dab;
  text-align: center;
  line-height: 50px;
}
.tabs {
  margin-top: 38px;
  border: 1px solid #dddddd;
  width: 398px;
  height: 67px;
  display: flex;
  font-size: 20px;
}
.tabs > div {
  flex: 1;
  font-size: 20px;
  height: 67px;
  line-height: 67px;
  text-align: center;
  font-weight: bold;
}
.tabs:first-child {
  border-right: 1px solid #ddd;
}
.tabs .tabac {
  background: #e0eefe;
}
.thead {
  background: #e0eefe;
  border: 1px solid #dddddd;
  /* width: 1490px; */
  height: 67px;
  line-height: 67px;
  border-right:0px;
  display: flex;
}
.thead > div {
  float: left;
  height: 67px;
  border-right: 1px solid #ddd;
  box-sizing: border-box;
  text-align: center;
  font-weight: bold;
  font-size: 20px;
}
.tbody {
  /* width: 1492px; */
  /* display: inline-block; */
  overflow: hidden;
  height: 60px;
  line-height: 60px;
  border: 1px solid #ddd;
  box-sizing: border-box;
  border-right:0px;
}
.tbody > div {
  height: 60px;
  /* line-height: 160px; */
  float: left;
  border-right: 1px solid #ddd;
  box-sizing: border-box;
  text-align: center;
  font-size: 18px;
  color: #4a4a4a;
  font-weight: bold;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.tbody > div > span {
  /* height: 30px;
  line-height: 30px; */
  /* padding: 0 20px; */
  white-space:normal; word-break:break-all;
  line-height: 20px;
}
.tbody > div > div {
  height: 30px;
  line-height: 30px;
  text-align: center;
  width: 240px;
}
.username {
  /* width: 200px; */
  width: 30%;
}
.parsr {
  /* width: 256px; */
  width: 12%;
}
.accmoney {
  /* width: 278px; */
  width: 12%;
}
.txmoney {
  /* width: 260px; */
  width: 12%;

}
.tbody .accmoney {
    color: #fe0000;
}
.ptmoney {
  /* width: 270px; */
  width: 12%;
}
.ctrl {
  /* width: 220px; */
  width: 22%;
  border-right: 0px;
  
}
.tbody .ctrl {
  cursor: pointer;
}
</style>


